﻿/*
* JxymJS 1.0
* js 基本操作类库
* 徐永明
* 2011-04-09
*Jxym.on(function () {
*            var embed = new Jxym.panel.EmbedPanel({
*                width: 800,
*                height: 200,
*                menu: false,
*                src: "flash_animation.swf",
*                renderTo: "div1"
*            });
*});
*/
var Jxym = {
    apply: function (obj, config) {
        for (var key in config) {
            obj[key] = config[key];
        }
    },
    on: function (fn) {
        var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
        if (isIE)
            window.attachEvent("onload", fn); //对于IE 
        else
            window.addEventListener("load", fn, false); //对于FireFox 
    },
    getDoc: function (s) {
        var k = s.substring(0, 1);
        var v = s.substring(1, s.length);
        if (s && k && v) {
            switch (k) {
                default:
                    return document.getElementsByTagName(v);
                    break;
                case "#":
                    return document.getElementById(v);
                    break;
            }
        }
    },
    ajax: {
        request: function (url) {
            var obj;
            if (window.ActiveXObject) {
                obj = new ActiveXObject('Microsoft.XMLHTTP');
            } else if (window.XMLHttpRequest) {
                obj = new XMLHttpRequest();
            }
            obj.open('GET', url, false);
            obj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            obj.send(null);
            return obj.responseText;
        }
    },
    panel: {
        EmbedPanel: function (config) {
            Jxym.apply(this, config);
            var el = document.createElement("embed");
            for (var key in config) {
                if (key != "renderTo") {
                    el.setAttribute(key, config[key]);
                }
            }
            var panel = document.getElementById(config.renderTo);
            panel.appendChild(el);
        }
    },
    tool: {
        img: {
            ResetWidth: function (element, max_width) {
                var element = document.getElementById(element);
                if (element) {
                    var items = element.getElementsByTagName('img');
                    if (items)
                        for (var i = 0; i < items.length; i++) {
                            if (items[i].width > max_width) {
                                items[i].width = max_width;
                            }
                        }
                }
            }
        },
        ActiveXObject: {
            isAcrobatPluginInstall: function () {
                //如果是firefox浏览器 
                if (navigator.plugins && navigator.plugins.length) {
                    for (x = 0; x < navigator.plugins.length; x++) {
                        if (navigator.plugins[x].name == 'Adobe Acrobat')
                            return true;
                    }
                }
                //下面代码都是处理IE浏览器的情况 
                else if (window.ActiveXObject) {
                    for (x = 2; x < 10; x++) {
                        try {
                            oAcro = eval("new ActiveXObject('PDF.PdfCtrl." + x + "');");
                            if (oAcro) {
                                return true;
                            }
                        }
                        catch (e) { }
                    }
                    try {
                        oAcro4 = new ActiveXObject('PDF.PdfCtrl.1');
                        if (oAcro4)
                            return true;
                    }
                    catch (e) { }
                    try {
                        oAcro7 = new ActiveXObject('AcroPDF.PDF.1');
                        if (oAcro7)
                            return true;
                    }
                    catch (e) { }
                }
            }
        }
    }
};